package cn.gok.homework;

class Person {
    private String name;
    private boolean sex;//true男,false女
    private int age;
    private boolean isMarried;//true结婚,false未婚

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public boolean getSex() {
        return sex;
    }

    public void setSex(boolean sex) {
        this.sex = sex;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public boolean isMarried() {
        return isMarried;
    }

    public void setMarried(boolean married) {
        isMarried = married;
    }

    public Person(String name, boolean sex, int age, boolean isMarried) {
        this.name = name;
        this.sex = sex;
        this.age = age;
        this.isMarried = isMarried;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", sex='" + sex + '\'' +
                ", age=" + age +
                '}';
    }

    public static boolean marryWith(Person p1, Person p2) {
        if (p1.isMarried == false && p2.isMarried == false) {
            if (p1.sex == p2.sex){
                System.out.println("性别相同，不能结婚");
            }
            else if ((p1.sex=true && p1.getAge() < 20) || (p2.sex=false && p2.getAge()<19) || (p1.sex=true && p1.getAge() < 19) || (p2.sex=false && p2.getAge()<20)){
                System.out.println("年龄不够，不能结婚");
            }else {
                System.out.println("可以结婚");
            }
        }else {
            System.out.println("一方已经结婚");

        }

        return true;
    }


    public void study(String school){
        System.out.println(this.name+"在"+school+"学习");
    }

}

public class homework3 {
    public static void main(String[] args) {
        Person p1 = new Person("aa",true,18,false);
        Person p2 = new Person("bb",false,20,false);
        Person.marryWith(p1,p2);
        System.out.println("-------------------------");

        int time =1;
        Person p3 = new Person("cc",true,22,false){
            @Override
            public void study(String school) {
                System.out.println(getName()+"在"+school+"学习了"+time+"年");
            }
        };
        p3.study("泉大");
    }




}